package com.ccl.iot.template;import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;

public class StandardDialog extends Dialog {

	public StandardDialog(Context context) {
		super(context);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		super.setOnShowListener(iShowListener);
	}
	
	protected boolean onCancel(){
		return true;
	}
	
	@Override
	public void cancel(){
		if (onCancel()){
			super.cancel();
		}
	}
	
	@Override
	public void onBackPressed() {
		if (onCancel()){
			super.onBackPressed();
		}
	}
	
	protected void onShow(){
		
	}
	
	private OnShowListener iOnShowListener = null;
	private OnShowListener iShowListener = new OnShowListener(){
		@Override
		public void onShow(DialogInterface dialog) {
			StandardDialog.this.onShow();
			
			if (iOnShowListener != null){
				iOnShowListener.onShow(dialog);
			}
		}
	};

	@Override
	public void setOnShowListener(OnShowListener listener) {
		iOnShowListener = listener;
	}
	
}
